package com.ks.community.controller;


import com.alibaba.excel.EasyExcel;
import com.atguigu.commonutils.R;
import com.ks.community.entity.Ingredient;
import com.ks.community.entity.excel.IngredientExcel;
import com.ks.community.entity.vo.IngredientVo;
import com.ks.community.listenter.IngredientListenter;
import com.ks.community.service.IngredientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dCoder
 * @since 2022-04-04
 */
@RestController
@RequestMapping("/community/ingredient")
public class IngredientController {
    @Autowired
    IngredientService ingredientService;
    @RequestMapping("/add")
    public R addIngredient(@RequestBody IngredientVo ingredientVo){
        ingredientService.addIngredient(ingredientVo);
        return R.ok();
    }

    @GetMapping("addIn")
    public R add(){
        String fileName = "D:/食材.xlsx";
        EasyExcel.read(fileName, IngredientExcel.class,new IngredientListenter(ingredientService)).sheet().doRead();
        return R.ok();
    }

}